package com.manor.paradise.adapter

import android.widget.ProgressBar
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.manor.common.utils.DateUtil
import com.manor.common.utils.scaleDown
import com.manor.paradise.R
import com.manor.paradise.bean.RecordHBean
import java.math.BigDecimal
import java.text.SimpleDateFormat


class HeartAdapter(layoutResId: Int, data: MutableList<RecordHBean>?) : BaseQuickAdapter<RecordHBean, BaseViewHolder>
(layoutResId, data) {

    override fun convert(baseViewHolder: BaseViewHolder, item: RecordHBean) {
        var tv_name = baseViewHolder.getView<TextView>(R.id.tv_name)
        tv_name.text = "爱心奖励  "+item.totalCrystalOre.scaleDown(4)


        var tv_hysc = baseViewHolder.getView<TextView>(R.id.tv_hysc)
        val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")

        if (item.spiritId == "1") {
            var asa: BigDecimal = item.activeDuration.subtract(item.activeDays)//可活跃时长
            var bsb: BigDecimal = BigDecimal(DateUtil.differentDays(simpleDateFormat.parse(item.currentTime), simpleDateFormat.parse(item.invalidDate.toString())).toString())
            var csc: BigDecimal = if ((asa).compareTo(bsb) <= 0) bsb else asa
            tv_hysc.text = "有效期：" + csc.toString() + "天"
        } else {
            var nnn = BigDecimal(DateUtil.differentDays(simpleDateFormat.parse(item.effectiveDate),
                    simpleDateFormat.parse(item.currentTime.toString())).toString())
            if ((nnn).compareTo(BigDecimal.ZERO) < 0) {
                tv_hysc.text = "有效期：" + item.activeDuration + "天"
            } else {
                val residue = if ( item.activeDuration.subtract(nnn).subtract(BigDecimal.ONE)  >= BigDecimal.ZERO)
                    item.activeDuration.subtract(nnn).subtract(BigDecimal.ONE)
                else
                    BigDecimal.ZERO

                tv_hysc.text = "有效期：${residue}天"
            }

        }


        var createTime = baseViewHolder.getView<TextView>(R.id.tv_createTime)
        createTime.text = "雇佣时间：" + item.createTime + ""
        var sc = item.activeDays.divide(item.activeDuration, 2, BigDecimal.ROUND_DOWN)
        var a = sc.multiply(BigDecimal("100")).intValueExact()
        var progress_bar_healthy = baseViewHolder.getView<ProgressBar>(R.id.progress_bar_healthy)
        progress_bar_healthy.progress = a
        var tv_time = baseViewHolder.getView<TextView>(R.id.tv_time);
        tv_time.setText("活跃时长" + a + "%")

    }

    override fun onViewRecycled(holder: BaseViewHolder) {
        super.onViewRecycled(holder)
    }

    override fun onViewAttachedToWindow(holder: BaseViewHolder) {
        super.onViewAttachedToWindow(holder)
    }


}
